var cLayer = null;
var cCallback = null;
var tmpLayer = null;
var cBtns = [];
function common_click() {
	if (cBtns.length) {
		if (cLayer) {
			cLayer.remove();
			$('#overlay').hide();
		}
		$.each(cBtns, function(k, v) {
			$("#" + v).unbind("click", common_click);
		});
	}
	if($(this).attr('id') != 'A_common_ok'){
		return;
	}
	cLayer.remove();
	if (cCallback) cCallback.call(this);
	cCallback = null;
}

function showCommonLayer(content, type, callback){
	var dialog_html = '';
	if(1 == type){//警告
		dialog_html = '<div class="A_layer" id="A_layer_common">'
						+'<div class="bg">'
						  +'<table border="0" cellspacing="0" cellpadding="0">'
						    +'<tbody>'
						      +'<tr>'
						        +'<td><div class="content">'
						            +'<div class="title">提示</div>'
						            +'<a href="javascript:void(0);" class="A_close" id="A_common_close"></a>'
						            +'<div class="layer_point">'
						              +'<dl class="point clearfix">'
						                +'<dt><span class="icon_warnM"></span></dt>'
						                +'<dd>'
						                  +'<p class="W_texta">'+content+'</p>'
						                +'</dd>'
						              +'</dl>'
						              +'<div class="btn"><a href="javascript:void(0);" class="A_btn_a" id="A_common_ok"><span>确认</span></a><a href="javascript:void(0);" class="A_btn_b" id="A_common_cancel"><span>取消</span></a></div>'
						            +'</div>'
						          +'</div></td>'
						      +'</tr>'
						    +'</tbody>'
						  +'</table>'
						+'</div></div>';		
	}else if(2 == type){//二次确认
		dialog_html = '<div class="A_layer" id="A_layer_common">'
						+'<div class="bg">'
						  +'<table border="0" cellspacing="0" cellpadding="0">'
						    +'<tbody>'
						      +'<tr>'
						        +'<td><div class="content">'
						            +'<div class="title">提示</div>'
						            +'<a href="javascript:void(0);" class="A_close" id="A_common_close"></a>'
						            +'<div class="layer_point">'
						              +'<dl class="point clearfix">'
						                +'<dt><span class="icon_askM"></span></dt>'
						                +'<dd>'
						                  +'<p class="W_texta">'+content+'</p>'
						                +'</dd>'
						              +'</dl>'
						              +'<div class="btn"><a href="javascript:void(0);" class="A_btn_a" id="A_common_ok"><span>确认</span></a><a href="javascript:void(0);" class="A_btn_b" id="A_common_cancel"><span>取消</span></a></div>'
						            +'</div>'
						          +'</div></td>'
						      +'</tr>'
						    +'</tbody>'
						  +'</table>'
						+'</div></div>';
	}else if(3 == type){//状态提示“处理中”
		dialog_html = '<div class="A_layer" id="A_layer_common">'
						+'<div class="bg">'
						  +'<table border="0" cellspacing="0" cellpadding="0">'
						    +'<tbody>'
						      +'<tr>'
						        +'<td><div class="content">'
						            +'<div class="title">状态</div>'
						            +'<a href="javascript:void(0);" class="A_close" id="A_common_close"></a>'
						            +'<div class="layer_statetip">'
						              +'<dl class="point clearfix">'
						                +'<dt><span class="loading_l"></span></dt>'
						                +'<dd>'
						                  +'<p class="W_texta">'+content+'</p>'
						                +'</dd>'
						              +'</dl>'			              
						            +'</div>'
						          +'</div></td>'
						      +'</tr>'
						    +'</tbody>'
						  +'</table>'
						+'</div></div>';
	}else if(4 == type){//状态提示“成功”
		dialog_html = '<div class="A_layer" id="A_layer_common">'
						+'<div class="bg">'
						  +'<table border="0" cellspacing="0" cellpadding="0">'
						    +'<tbody>'
						      +'<tr>'
						        +'<td><div class="content">'
						            +'<div class="title">状态</div>'
						            +'<a href="" class="A_close" id="A_common_close"></a>'
						            +'<div class="layer_statetip">'
						              +'<dl class="point clearfix">'
						                +'<dt><span class="icon_succM"></span></dt>'
						                +'<dd>'
						                  +'<p class="W_texta">'+content+'</p>'
						                +'</dd>'
						              +'</dl>'
						              +'<div class="btn"><a href="javascript:void(0);" class="A_btn_b" id="A_common_cancel"><span>关闭</span></a></div>'
						            +'</div>'
						          +'</div></td>'
						      +'</tr>'
						    +'</tbody>'
						  +'</table>'
						+'</div></div>';
	}else if(5 == type){//状态提示“失败”
		dialog_html = '<div class="A_layer" id="A_layer_common">'
						+'<div class="bg">'
						  +'<table border="0" cellspacing="0" cellpadding="0">'
						    +'<tbody>'
						      +'<tr>'
						        +'<td><div class="content">'
						            +'<div class="title">状态</div>'
						            +'<a href="javascript:void(0);" class="A_close" id="A_common_close"></a>'
						            +'<div class="layer_statetip">'
						              +'<dl class="point clearfix">'
						                +'<dt><span class="icon_warnM"></span></dt>'
						                +'<dd>'
						                  +'<p class="W_texta">'+content+'</p>'
						                +'</dd>'
						              +'</dl>'
						              +'<div class="btn"><a href="javascript:void(0);" class="A_btn_b" id="A_common_cancel"><span>关闭</span></a></div>'
						            +'</div>'
						          +'</div></td>'
						      +'</tr>'
						    +'</tbody>'
						  +'</table>'
						+'</div></div>';
	}
	
	$("body").append(dialog_html);
	var areaHeight = window.top.document.documentElement.clientHeight;
	var areaWidth = document.documentElement.clientWidth;
	if(self != top){
		if(navigator.userAgent.indexOf("Firefox") > 0 || navigator.userAgent.indexOf("MSIE") > 0){
			var location_top = window.top.document.documentElement.scrollTop + (areaHeight - $("#A_layer_common").height()) / 2 -70;
		}else{
			var location_top = window.top.document.body.scrollTop + (areaHeight - $("#A_layer_common").height()) / 2 -70;
		}
	}else{
		if(navigator.userAgent.indexOf("Firefox") > 0 || navigator.userAgent.indexOf("MSIE") > 0){
			var location_top = window.top.document.documentElement.scrollTop + (areaHeight - $("#A_layer_common").height()) / 2;
		}else{
			var location_top = document.body.scrollTop + (areaHeight - $("#A_layer_common").height()) / 2;
		}
	}
	$("#A_layer_common").css({
		"position": "absolute",
		"z-index": "2010",
		"left": document.documentElement.scrollLeft + (areaWidth - $("#A_layer_common").width()) / 2,
		"top": location_top
	});
	
	var btns = ["A_common_close", "A_common_ok", "A_common_cancel"];		
	callback = callback || function(){};		
	cLayer = $("#A_layer_common");
	cCallback = callback;
	$.each(btns, function(key, val) {
		$("#" + val).bind("click", common_click);
	});		
	cBtns = btns;
	return;
}

function link_click() {
	if (cBtns.length) {
		if (cLayer) {
			cLayer.hide();
		}
		
		$.each(cBtns, function(k, v) {
			$("#" + v).unbind("click", link_click);
		});
	}
	$("body").append(tmpLayer);
	tmpLayer.hide();
	cLayer.remove();
	if (cCallback) cCallback.call(this);
	cCallback = null;
}
function showEditLayer(layer_id, title, btns, callback){
	var dialog_html = '';
	
		dialog_html = '<div class="A_layer" id="A_layer_editlayer">'
						+'<div class="bg">'
						  +'<table border="0" cellspacing="0" cellpadding="0">'
						    +'<tbody>'
						      +'<tr>'
						        +'<td><div class="content">'
						            +'<div class="title">' + title + '</div>'
						            +'<a href="javascript:void(0);" class="A_close" id="edit_layer_close"></a>'
						            +'<div class="layer_form" id="parent_layer_form">'
						            //<div></div>此处添加弹出内容代码
						            +'</div>'
						          +'</div></td>'
						      +'</tr>'
						    +'</tbody>'
						  +'</table>'
						+'</div></div>';
		$("body").append(dialog_html);
		
		$("#"+layer_id).appendTo("#parent_layer_form");
		
		if (cBtns.length) {			
			$.each(cBtns, function(k, v) {
				$("#" + v).unbind("click", link_click);
			});
		}	
		var areaHeight = window.top.document.documentElement.clientHeight;
		var areaWidth = document.documentElement.clientWidth;
		
		
		if(self != top){
			if(navigator.userAgent.indexOf("Firefox") > 0 || navigator.userAgent.indexOf("MSIE") > 0){
				var location_top = window.top.document.documentElement.scrollTop + (areaHeight - $("#A_layer_editlayer").height() - $("#"+layer_id).height()) / 2 -70;
			}else{
				var location_top = window.top.document.body.scrollTop + (areaHeight - $("#A_layer_editlayer").height() - $("#"+layer_id).height()) / 2 -70;
			}			
		}else{
			if(navigator.userAgent.indexOf("Firefox") > 0 || navigator.userAgent.indexOf("MSIE") > 0){
				var location_top = window.top.document.documentElement.scrollTop + (areaHeight - $("#A_layer_editlayer").height() - $("#"+layer_id).height()) / 2
			}else{
				var location_top = document.body.scrollTop + (areaHeight - $("#A_layer_editlayer").height() - $("#"+layer_id).height()) / 2
			}			
		}
		$("#A_layer_editlayer").css({
			"position": "absolute",
			"z-index": "2010",
			"left": $(document).scrollLeft() + (areaWidth - $("#"+layer_id).width()) / 2,
			"top": location_top
		});
		callback = callback || function(){};		
		cLayer = $("#A_layer_editlayer");
		tmpLayer = $("#"+layer_id);
		cCallback = callback;
		$("#"+layer_id).show();
		
		if(!btns){
			btns = [];
		}
		btns.push('edit_layer_close');
		$.each(btns, function(key, val) {
			$("#" + val).bind("click", link_click);
		});		
		cBtns = btns;
	
	return;
}